<?php


namespace app\common\library;

use think\Paginator;

/**
 * 通知lib
 */
class Show
{
    /**
     * Notes:成功数组通知
     * @param array $data
     * @param string $msg
     * @param int $code
     * @return array
     */
    public static function success($data = [], string $msg = 'success', int $code = Code::SUCCESS): array
    {
        return [
            'code'      => $code,
            'msg'       => $msg,
            'data'      => $data,
        ];
    }

    /**
     * Notes:失败数组通知
     * @param string $msg
     * @param int $code
     * @return array
     */
    public static function error(string $msg = '', int $code = Code::FAILED, $data = []): array
    {
        return [
            'code'      => $code,
            'msg'       => $msg,
            'data'      => $data,
        ];
    }


    public static function paginate(Paginator $list)
    {
        return [
            'code'      => Code::SUCCESS,
            'msg'       => 'success',
            'data'      => [
                'total'   => $list->total(),
                'per_page'   => $list->listRows(),
                'current_page' => $list->currentPage(),
                'last_page' => ceil($list->total()/$list->listRows()),
                'data'    => $list->getCollection(),
            ]
        ];
    }
}